<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('添加调度配置')" />
</head>
<body class="white-bg">

  <div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-job-add" th:object="${job}">
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">Job分组：</label>
        <div class="col-sm-9">
          <input name="jobGroup" placeholder="Job所属的组" th:field="*{jobGroup}" class="form-control" type="text" autocomplete="off" required />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">Job名称：</label>
        <div class="col-sm-9">
          <input name="jobName" class="form-control" type="text" autocomplete="off" required />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">Job状态：</label>
        <div class="col-sm-9">
          <select name="jobState" class="form-control m-b" th:with="enum=${@disjobService.enums('JobState')}">
            <option th:each="e : ${enum}" th:text="${e.desc}" th:value="${e.value}" th:field="*{jobState}"></option>
          </select>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">Job类型：</label>
        <div class="col-sm-9">
          <select name="jobType" class="form-control m-b" th:with="enum=${@disjobService.enums('JobType')}">
            <option th:each="e : ${enum}" th:text="${e.desc}" th:value="${e.value}" th:field="*{jobType}"></option>
          </select>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">Job处理器：</label>
        <div class="col-sm-9">
          <textarea rows="3" name="jobHandler" class="form-control" placeholder="支持：处理器类名、Spring bean name、DAG表达式、源码" required>[(*{jobHandler})]</textarea>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">Job参数：</label>
        <div class="col-sm-9">
          <textarea rows="3" name="jobParam" class="form-control">[(*{jobParam})]</textarea>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">重试配置：</label>
        <div class="col-sm-3">
          <select name="retryType" class="form-control m-b" th:with="enum=${@disjobService.enums('RetryType')}">
            <option th:each="e : ${enum}" th:text="${e.desc}" th:value="${e.value}" th:field="*{retryType}"></option>
          </select>
        </div>
        <div class="col-sm-3">
          <input name="retryCount" placeholder="最大重试次数" class="form-control" th:field="*{retryCount}" type="text" autocomplete="off" />
        </div>
        <div class="col-sm-3">
          <input name="retryInterval" placeholder="重试间隔(毫秒)" th:field="*{retryInterval}" class="form-control" type="text" autocomplete="off" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label">Job有效期：</label>
        <div class="col-sm-9">
          <div class="input-daterange input-group">
            <input name="startTime" th:value="${#dates.format(job.startTime, 'yyyy-MM-dd')}" type="text" class="input-sm form-control" id="laydate-startTime" placeholder="yyyy-MM-dd" autocomplete="off" />
            <span class="input-group-addon"> ~ </span>
            <input name="endTime" th:value="${#dates.format(job.endTime, 'yyyy-MM-dd')}" type="text" class="input-sm form-control" id="laydate-endTime" placeholder="yyyy-MM-dd" autocomplete="off" />
          </div>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">触发器配置(<a href="http://cron.qqe2.com/" target="_blank">CronExpr</a>)：</label>
        <div class="col-sm-3">
          <select name="triggerType" class="form-control m-b" th:with="enum=${@disjobService.enums('TriggerType')}">
            <option th:each="e : ${enum}" th:text="${e.desc}" th:value="${e.value}" th:field="*{triggerType}"></option>
          </select>
        </div>
        <div class="col-sm-6">
          <input name="triggerValue" th:field="*{triggerValue}" class="form-control" type="text" autocomplete="off" placeholder="触发器类型对应的值：Cron表达式、时间格式、固定周期json格式串、父jobId等" required />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">执行冲突策略：</label>
        <div class="col-sm-9">
          <select name="collidedStrategy" class="form-control m-b" th:with="enum=${@disjobService.enums('CollidedStrategy')}">
            <option th:each="e : ${enum}" th:text="${e.desc}" th:value="${e.value}" th:field="*{collidedStrategy}"></option>
          </select>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">过期策略：</label>
        <div class="col-sm-9">
          <select name="misfireStrategy" class="form-control m-b" th:with="enum=${@disjobService.enums('MisfireStrategy')}">
            <option th:each="e : ${enum}" th:text="${e.desc}" th:value="${e.value}" th:field="*{misfireStrategy}"></option>
          </select>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-3 control-label is-required">路由策略：</label>
        <div class="col-sm-9">
          <select name="routeStrategy" class="form-control m-b" th:with="enum=${@disjobService.enums('RouteStrategy')}">
            <option th:each="e : ${enum}" th:text="${e.desc}" th:value="${e.value}" th:field="*{routeStrategy}"></option>
          </select>
        </div>
      </div>
    </form>
  </div>

  <th:block th:include="include :: footer" />
  <script th:inline="javascript">
    var prefix = ctx + "disjob/job"

    $(function () {
      layui.use('laydate', function () {
        var laydate = layui.laydate;
        var startDate = laydate.render({
          elem: '#laydate-startTime',
          max: $('#laydate-endTime').val(),
          theme: 'molv',
          trigger: 'click',
          done: function (value, date) {
            // 结束时间大于开始时间
            if (value !== '') {
              endDate.config.min.year = date.year;
              endDate.config.min.month = date.month - 1;
              endDate.config.min.date = date.date;
            } else {
              endDate.config.min.year = '';
              endDate.config.min.month = '';
              endDate.config.min.date = '';
            }
          }
        });
        var endDate = laydate.render({
          elem: '#laydate-endTime',
          min: $('#laydate-startTime').val(),
          theme: 'molv',
          trigger: 'click',
          done: function (value, date) {
            // 开始时间小于结束时间
            if (value !== '') {
              startDate.config.max.year = date.year;
              startDate.config.max.month = date.month - 1;
              startDate.config.max.date = date.date;
            } else {
              startDate.config.max.year = '';
              startDate.config.max.month = '';
              startDate.config.max.date = '';
            }
          }
        });
      });
    });

    $("#form-job-add").validate({
      focusCleanup: true,
      rules: {
        retryCount: {
          digits: true,
          min: 0
        },
        retryInterval: {
          digits: true,
          min: 0
        }
      }
    });

    function submitHandler() {
      if ($.validate.form()) {
        $.operate.save(prefix + "/add", $('#form-job-add').serialize());
      }
    }
  </script>

</body>
</html>
